<% content_for :page_title do %>
  <%= Spree.t(:users) %>
<% end %>

<% content_for :page_actions do %>
  <%= button_link_to Spree.t(:new_user), new_admin_user_url, class: "btn-success", icon: 'add.svg', id: 'admin_new_user_link' %>
<% end if can? :create, Spree::user_class %>

<% content_for :table_filter_title do %>
  <%= Spree.t(:search) %>
<% end %>

<% content_for :table_filter do %>
  <div data-hook="admin_users_index_search">
    <%= search_form_for [:admin, @search], url: spree.admin_users_url do |f| %>
      <div class="form-group">
        <%= f.label :email_cont, Spree.t(:email) %>
        <%= f.text_field :email_cont, class: "form-control js-quick-search-target js-filterable" %>
      </div>
      <div class="row">
        <div class="col-12 col-lg-6">
          <div class="form-group">
            <%= f.label :bill_address_firstname_cont, Spree.t(:first_name) %>
            <%= f.text_field :bill_address_firstname_cont, class: 'form-control js-filterable' %>
          </div>
        </div>
        <div class="col-12 col-lg-6">
          <div class="form-group">
            <%= f.label :bill_address_lastname_cont, Spree.t(:last_name) %>
            <%= f.text_field :bill_address_lastname_cont, class: 'form-control js-filterable' %>
          </div>
        </div>
      </div>
      <% if Spree::Config[:company] %>
        <div class="form-group">
          <%= f.label :bill_address_company_cont, Spree.t(:company) %>
          <%= f.text_field :bill_address_company_cont, class: 'form-control js-filterable' %>
        </div>
      <% end %>
      <div data-hook="admin_users_index_search_buttons" class="form-actions">
        <%= button Spree.t(:search), 'search.svg' %>
      </div>
    <% end %>
  </div>
<% end %>

<% if @users.any? %>
  <div class="table-responsive">
    <table class="table" id="listing_users" data-hook>
      <thead>
        <tr data-hook="admin_users_index_headers">
          <th>
            <%= sort_link @search,:email, Spree.t(:user), {}, {title: 'users_email_title'} %>
          </th>
          <th data-hook="admin_users_index_header_actions" class="actions"></th>
        </tr>
      </thead>
      <tbody>
        <% @users.each do |user| %>
          <tr id="<%= spree_dom_id user %>" data-hook="admin_users_index_rows">
            <td class='user_email'><%= link_to user.email, edit_admin_user_url(user) %></td>
            <td data-hook="admin_users_index_row_actions" class="actions actions-2 text-right">
              <%= link_to_edit user, no_text: true if can?(:edit, user) %>
              <%= link_to_delete user, no_text: true if can?(:delete, user) %>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
  </div>
<% else %>
  <div class="alert alert-info no-objects-found">
    <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree.user_class)) %>,
    <%= link_to Spree.t(:add_one), new_object_url %>!
  </div>
<% end %>

<%= paginate @users, theme: 'admin-twitter-bootstrap-4' %>
